package org.cxy;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import java.util.List;

public class ChatSessionParser {

    // 对应的类结构
    public static class Response {
        @SerializedName("code")
        public int code;
        @SerializedName("msg")
        public String msg;
        @SerializedName("data")
        public Data data;
    }

    public static class Data {
        @SerializedName("biz_code")
        public int bizCode;
        @SerializedName("biz_msg")
        public String bizMsg;
        @SerializedName("biz_data")
        public BizData bizData;
    }

    public static class BizData {
        @SerializedName("chat_sessions")
        public List<ChatSession> chatSessions;
    }

    public static class ChatSession {
        @SerializedName("id")
        public String id;
        @SerializedName("title")
        public String title;
    }

    // 假设 jsonStr 是你提供的 JSON 字符串
    private static final String jsonStr = """
            {
                "code": 0,
                "msg": "",
                "data": {
                    "biz_code": 0,
                    "biz_msg": "",
                    "biz_data": {
                        "chat_sessions": [
                            {
                                "id": "67ffc801-2141-4a2b-a9ef-04bfa6b267cf",
                                "title": "腰椎锻炼建议",
                                "title_type": "USER",
                                "pinned": true,
                                "updated_at": 1761630159.777
                            },
                            {
                                "id": "6885b698-638d-47db-9bff-d9664b48cac8",
                                "title": "气柱袋与葫芦膜对比分析",
                                "title_type": "SYSTEM",
                                "pinned": false,
                                "updated_at": 1761553408.413
                            },
                            {
                                "id": "17881717-5463-4849-b9e1-715338de3303",
                                "title": "快递气柱袋购买与充气指南",
                                "title_type": "SYSTEM",
                                "pinned": false,
                                "updated_at": 1761297534.602
                            },
                            {
                                "id": "2b13c4a5-56ef-458c-b03b-c7e478be9326",
                                "title": "集杯活动库存更新任务解析",
                                "title_type": "SYSTEM",
                                "pinned": false,
                                "updated_at": 1761286064.995
                            },
                            {
                                "id": "fec6f6e9-cea3-4f49-9886-06ac5f318699",
                                "title": "汇率计算",
                                "title_type": "USER",
                                "pinned": false,
                                "updated_at": 1760416279.101
                            },
                            {
                                "id": "e335d06f-99b7-4b3a-84b4-5a66ac69a8eb",
                                "title": "爬虫4khd",
                                "title_type": "WIP",
                                "pinned": false,
                                "updated_at": 1760197044.743
                            },
                            {
                                "id": "30630ae9-0bfe-4a20-a20f-6d0f2b068959",
                                "title": "周期抽奖活动策划与执行方案",
                                "title_type": "SYSTEM",
                                "pinned": false,
                                "updated_at": 1760088154.819
                            }
                        ],
                        "has_more": false
                    }
                }
            }
            """;

    // 主方法
    public static void main(String[] args) {

        // 使用 Gson 解析
        Gson gson = new Gson();
        Response response = gson.fromJson(jsonStr, Response.class);

        if (response.code == 0 && response.data != null && response.data.bizData != null) {
            for (ChatSession session : response.data.bizData.chatSessions) {
                System.out.printf("{\"chat_session_id\": \"%s\"}  // %s%n", session.id, session.title);
            }
        } else {
            System.err.println("解析失败或数据异常");
        }
    }
}